package com.hejr.springboot2_001.controller;

import com.google.common.collect.Lists;
import com.hejr.springboot2_001.entity.UserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * SpringBoot2.0整合Freemarker和JSP，以及全局异常捕获
 */
@Controller
@Slf4j
public class IndexController {

    /**
     * Freemarker请求入口
     * @param map
     * @return
     */
    @RequestMapping("/ftlIndex")
    public String fltIndex(Map<String, Object> map) {
        map.put("userName", "何金荣");
        map.put("sex", "1");
        List<String> listResult = Lists.newArrayList();
        listResult.add("张三");
        listResult.add("李四");
        listResult.add("五老五");
        map.put("listResult", listResult);

        return "ftlIndex";
    }

    /**
     * Jsp请求入口
     * @param map
     * @return
     */
    @RequestMapping("/jspIndex")
    public String jspIndex(Map<String, Object> map) {
        map.put("currentUserName", "何金荣");
        List<UserEntity> listResult = Lists.newArrayList(
                new UserEntity("111", "古天乐"),
                new UserEntity("222", "胡歌"),
                new UserEntity("333", "黄功利")
        );
        map.put("userList", listResult);
        return "jspIndex";
    }




    @RequestMapping("/index")
    public String index() {
        return "Hello, SpringBoot2.1.3";
    }

}
